package com.shop.service.impl;

import com.github.pagehelper.PageInfo;
import com.shop.entity.Brand;
import com.shop.mapper.BrandMapper;
import com.shop.service.BrandService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("brandService")
@RequiredArgsConstructor
@Transactional(rollbackFor = RuntimeException.class,
        propagation = Propagation.REQUIRED)
public class BrandServiceImpl implements BrandService {
    private final BrandMapper brandMapper;
    @Override
    public PageInfo<Brand> listBrand(Integer pageNum, Integer pageSize) {
        List<Brand> brands = brandMapper.listBrand(pageNum, pageSize);
        return new PageInfo<>(brands);
    }

    @Override
    public Brand getBrand(String name) {
        return brandMapper.getBrand(name);
    }

    @Override
    public Brand getBrandById(Integer id) {
        return brandMapper.getBrandById(id);
    }

    @Override
    public void addBrand(Brand brand) {
        brandMapper.addBrand(brand);
    }

    @Override
    public void deleteBrand(Integer id) {
        brandMapper.deleteBrand(id);
    }

    @Override
    public void updateBrand(Brand brand) {
        brandMapper.updateBrand(brand);
    }

    @Override
    public int getTotal() {
        return brandMapper.getTotal();
    }
}
